package com.ttl.bc.vat.inputtax.db;

import java.util.Date;

import org.apache.struts.action.ActionForm;

import com.ttl.bc.ap.debitnote2.action.BCDebitNote2Form;
import com.ttl.bc.ap.invoice.action.BCAPInvoice2Form;
import com.ttl.bc.ap.stkrefund.action.BCStkRefundForm;
import com.ttl.bc.vat.inputtax.bean.BCInputTaxBean;
import com.ttl.common.util.CommonUtils;

public class BCInputTaxBO {

	public static Object getObject(ActionForm form) {
		
		BCAPInvoice2Form invForm = (BCAPInvoice2Form)form;  
		
		BCInputTaxBean tax = new BCInputTaxBean();				
		tax.setSaveFrom(1);
		tax.setDocNo(invForm.getDocNo());
		tax.setBookCode("04");
		tax.setSource(2);
		tax.setDocDate(CommonUtils.convertStringToDate( invForm.getDocDate()));

		tax.setTaxDate(CommonUtils.convertStringToDate(invForm.getTaxDate()));
		tax.setTaxDate2(CommonUtils.convertStringToDate(invForm.getTaxDate()));

		
		tax.setTaxNo(invForm.getTaxNo());
		tax.setApCode(invForm.getApCode());
		tax.setShortTaxDesc("ซื้อสินค้า");
		tax.setTaxRate(Double.valueOf(invForm.getTaxRate()));
		tax.setProcess(1);
		tax.setBeforeTaxAmount(Double.valueOf(invForm.getSumOfItemAmount()));
		tax.setTaxAmount(Double.valueOf(invForm.getTaxAmount()));		
		tax.setExceptTaxAmount(0.0);
		tax.setZeroTaxAmount(0.0);
		tax.setLineNumber(0);
		tax.setIsMultiCurrency(0);
		tax.setfAmount(0.0);
		tax.setExchangeRate(0.0);
		tax.setReturnTax(0);// 0=ขอคืนภาษีได้, 1=ขอคือภาษีไม่ได้ 
		tax.setTaxGroup(invForm.getBillGroup());
		tax.setCreatorCode(invForm.getCreatorCode());
		tax.setCreateDateTime(new Date());
		tax.setCancelOutPeriod(0);
		tax.setIsCancel(0);
		tax.setAvgTaxRate(0.0);
		
		tax.setIsExport(0);
		
		return tax;
	}

	public static BCInputTaxBean getObjectDN(ActionForm form) {
		
		BCDebitNote2Form dnForm = (BCDebitNote2Form)form;  
		
		BCInputTaxBean tax = new BCInputTaxBean();				
		tax.setSaveFrom(4);
		tax.setDocNo(dnForm.getDocNo());
		tax.setBookCode("01");
		tax.setSource(4);
		tax.setDocDate(CommonUtils.convertStringToDate( dnForm.getDocDate()));

		tax.setTaxDate(CommonUtils.convertStringToDate(dnForm.getTaxDate()));
		tax.setTaxDate2(CommonUtils.convertStringToDate(dnForm.getTaxDate()));

		
		tax.setTaxNo(dnForm.getTaxNo());
		tax.setApCode(dnForm.getApCode());
		tax.setShortTaxDesc("ยอดเพิ่มหนี้เจ้าหนี้ (data from ittl)");
		tax.setTaxRate(dnForm.getTaxRate());
		tax.setProcess(1);
		tax.setBeforeTaxAmount(Double.valueOf(dnForm.getSumOfItemAmount()));
		tax.setTaxAmount(Double.valueOf(dnForm.getTaxAmount()));		
		tax.setExceptTaxAmount(0.0);
		tax.setZeroTaxAmount(0.0);
		tax.setLineNumber(0);
		tax.setIsMultiCurrency(0);
		tax.setfAmount(0.0);
		tax.setExchangeRate(0.0);
		tax.setReturnTax(0);// 0=ขอคืนภาษีได้, 1=ขอคือภาษีไม่ได้ 
		tax.setTaxGroup(dnForm.getBillGroup());
//		tax.setCreatorCode(dnForm.getCreatorCode());
		tax.setCreateDateTime(new Date());
		tax.setCancelOutPeriod(0);
		tax.setIsCancel(0);
		tax.setAvgTaxRate(0.0);
		
		tax.setIsExport(0);
		
		return tax;
	}

	public static BCInputTaxBean getObjectCN(ActionForm form) {
		
		BCStkRefundForm cnForm = (BCStkRefundForm)form;  
		
		BCInputTaxBean tax = new BCInputTaxBean();				
		tax.setSaveFrom(5);
		tax.setDocNo(cnForm.getDocNo());
		tax.setBookCode("01");
		tax.setSource(3);
		tax.setDocDate(CommonUtils.convertStringToDate( cnForm.getDocDate()));

		tax.setTaxDate(CommonUtils.convertStringToDate(cnForm.getTaxDate()));
		tax.setTaxDate2(CommonUtils.convertStringToDate(cnForm.getTaxDate()));

		
		tax.setTaxNo(cnForm.getTaxNo());
		tax.setApCode(cnForm.getApCode());
		tax.setShortTaxDesc("ส่งคืนสินค้า/ลดหนี้ (data from ittl)");
		tax.setTaxRate(cnForm.getTaxRate());
		tax.setProcess(2);
		tax.setBeforeTaxAmount(Double.valueOf(cnForm.getSumOfItemAmount()));
		tax.setTaxAmount(Double.valueOf(cnForm.getTaxAmount()));		
		tax.setExceptTaxAmount(0.0);
		tax.setZeroTaxAmount(0.0);
		tax.setLineNumber(0);
		tax.setIsMultiCurrency(0);
		tax.setfAmount(0.0);
		tax.setExchangeRate(0.0);
		tax.setReturnTax(0);// 0=ขอคืนภาษีได้, 1=ขอคือภาษีไม่ได้ 
		tax.setTaxGroup(cnForm.getBillGroup());
//		tax.setCreatorCode(cnForm.getCreatorCode());
		tax.setCreateDateTime(new Date());
		tax.setCancelOutPeriod(0);
		tax.setIsCancel(0);
		tax.setAvgTaxRate(0.0);
		
		tax.setIsExport(0);
		
		return tax;
	}

}
